package com.csw.compose.ui.module.component.base

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Email
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.csw.compose.theme.pagePadding
import com.csw.compose.ui.Destination
import com.csw.compose.ui.components.BodyText
import com.csw.compose.ui.components.LabelText
import com.csw.compose.ui.components.NormalSpacer
import com.csw.compose.ui.components.PrimaryTitle
import com.csw.compose.ui.components.UlItem
import com.csw.compose.ui.module.BasePage


@Preview
@Composable
fun BadgePagePreview() {
    BasePage({}, "徽章（Badge）") {
        BadgePage()
    }
}

class BadgePageData {
    companion object : Destination("BadgedPage")
}

/**
 *[参考](https://developer.android.google.cn/develop/ui/compose/components/badges?hl=zh-cn)
 */
@Composable
fun BadgePage() {
    Column(
        modifier = Modifier
            .padding(horizontal = pagePadding)
            .verticalScroll(rememberScrollState())
    ) {
        PrimaryTitle("简介")
        BodyText("徽章，通常用于显示提示消息数量")
        NormalSpacer()
        BadgedBox(badge = {
            Badge(
                containerColor = MaterialTheme.colorScheme.error,
                contentColor = MaterialTheme.colorScheme.onError
            ) {
                Text("999")
            }
        }) {
            Icon(Icons.Filled.Email, "", tint = MaterialTheme.colorScheme.primary)
        }
        UlItem("BadgedBox")
        LabelText("徽章容器，将徽章放置到内容的右上角")
        NormalSpacer()
        UlItem("Badge")
        LabelText("徽章，提供背景与内容设置，背景会自适应为圆形或跑道形状")
        NormalSpacer()
    }
}